package com.fpno1.update;

import com.fpno2.JDBCUtil.JDBCUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class PreparedStatementUpdateTest {

    @Test
    public void testCommonUpdate() throws Exception {
        String sql="update user_table set user= ? where password= ?";
        update(sql,"刘亦菲","123456");
    }


    //通用的增删改
    public void update(String sql,Object... args) throws Exception {
        Connection con = JDBCUtils.getConnection();
        PreparedStatement ps = con.prepareStatement(sql);
        for (int i=0;i<args.length;i++){
            ps.setObject(i+1,args[i]);
        }
        ps.execute();
        JDBCUtils.closeResource(con,ps);
    }


}
